package com.region.loadbalancer.policy;

import com.region.loadbalancer.group.Server;

import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

/**
 * Random Strategy
 *
 * @author liujieyu
 * @date 2023/5/27 14:59
 * @desciption
 */
public class RandomPolicy implements BalancerPolicy{

    private ThreadLocalRandom random = ThreadLocalRandom.current();

    @Override
    public Server choose(List<Server> servers) {
        return servers.get(random.nextInt(servers.size()));
    }

    @Override
    public BalancerPolicy deepClone() {
        return new RandomPolicy();
    }
}
